
const app = getApp()
const $api = require('../../../utils/api.js').API;

Page({
    data: {
        list:{},
        formShow:false,
        remark:''
    },
    onLoad: function(){
        wx.showLoading()
        this.getlist();
    },
    getlist: function(){
        var that = this
        var data ={'uid':wx.getStorageSync('uid')}
        $api.get('problem/words',data).then(res => {
            if(res.data.code == 1){
                wx.hideLoading()
                that.setData({
                    list:res.data.data
                })
            }
        })
    },
    delete:function(e){
        var id = e.currentTarget.dataset.id
        var data = {id:id}
        var that = this
        $api.delete('problem/wordsDel',data).then(res => {
            if(res.data.code == 1){
                wx.showToast({
                    title:'删除成功',
                    duration:3000,
                    mask:true,
                    icon:'success', 
                })
                wx.showLoading()
                that.getlist();
            }
        })
    },
    wordsAdd:function(){
        this.setData({
            formShow:true
        })
    },
    wordsClose:function(){
        this.setData({
            formShow:false
        })
    },
    bindKeyInput:function(e){
        this.setData({
            remark:e.detail.value
        })
    },
    add:function(){
        if(!this.data.remark){
            wx.showToast({
                title:'请输入常用语',
                duration:3000,
                mask:true,
                icon:'none', 
            })
            return;
        }
        var data = {uid:wx.getStorageSync('uid'),remark:this.data.remark}
        var that = this
        $api.post('problem/wordsAdd',data).then(res => {
            if(res.data.code == 1){
                wx.showToast({
                    title: '添加成功!!',//提示文字
                    duration:3000,//显示时长
                    mask:true,//是否显示透明蒙层，防止触摸穿透，默认：false  
                    icon:'success', //图标，支持"success"、"loading"   
                    success:function(){
                      setTimeout(function(){
                        wx.navigateBack({//返回
                            delta: 1
                          })
                      },3000) //延迟时间 这里是
                    }
                  })
            }
        })
    },
    onShareAppMessage: function() {
        return {
            title: "天意美业直通车",
            path: "/pages/index/index?puid="+wx.getStorageSync('uid')
        };
      }
});